<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>代考勤设置</title>
    <link rel="stylesheet" type="text/css" href="../lib/laydate.css"/>
    <link rel="stylesheet" type="text/css" href="../lib/pagination/style/pagination.css"/>
    <link rel="stylesheet" type="text/css" href="../css/base.css"/>
    <script type="text/javascript" src="../js/common/language.js" ></script>
    <script type="text/javascript" src="../js/news/jquery-1.9.1.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/news/page.js"></script>
    <script src="/lib/layer/layer.js?20201106"></script>
    <script src="/js/base/base.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/js/ajaxupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script src="../lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <%--<script src="../lib/layer/layer.js?20201106"></script>--%>
    <style>
        a{
            text-decoration: none;
            color: #207bd6;
        }

        .buttonDiv>div{
            float: left;
            margin: 20px 10px;
        }
        .fileDone select{
            width: 160px;
            height:28px;
        }
        #tr_td tr:nth-child(odd){
            background-color: #fff;
        }
        input{
            float: none;
        }
        .newMange input[type="text"]{
            width: 260px;
            height: 30px;
        }
        select{
            width: 260px;
            height: 30px;
        }
        textarea{
            width: 260px;
            height: 50px;
            vertical-align: middle;
        }
        a{
            text-decoration: none;
            color: #207bd6;
        }
        .newTbale tr td{
            border-right: #ccc 1px solid;
            padding: 5px;
        }
        .divTable{
            width: 60%;
            margin: 0px auto;
        }
        .divTable table{
            width: 100%;
        }
        .divTable table tr th{
            padding: 8px;
            font-size: 13pt;
            color: #2F5C8F;
        }
        .divTable table tr td{
            text-align: center;
        }
        .divBtn{
            float: right !important;
            width: 103px;
            height: 28px;
            background: #2b7fe0;
            color: #fff;
            font-size: 14px;
            line-height: 28px;
            margin-right: 4%;
            margin-top: 20px;
            cursor: pointer;
            border-radius: 4px;
        }

        .return{
            width: 103px;
            height: 28px;
            background: #2b7fe0;
            border-radius: 4px;
            cursor: pointer;
            text-align: center;
            color: #ffffff;
            line-height: 28px;
            float: right;
            font-size: 14px;
            margin: 20px 70px 0 0;
        }
        .return a{
            color: #ffffff;
            padding:0 30px;
        }
        .applicable {
            width:60%;
            margin: 0 auto;
        }
        .applicableCon {
            width:80%;
            margin: 30px auto;
        }
        .addGeneration {
            width: 103px;
            height: 28px;
            background: #2b7fe0;
            border-radius: 4px;
            cursor: pointer;
            text-align: center;
            color: #ffffff;
            line-height: 28px;
            float: left;
            font-size: 14px;
            color: #ffffff;
            padding: 0 30px;
            margin-left: 250px;
        }
        .preserve {
            width: 103px;
            height: 28px;
            background: #2b7fe0;
            border-radius: 4px;
            cursor: pointer;
            text-align: center;
            color: #ffffff;
            line-height: 28px;
            float: left;
            font-size: 14px;
            color: #ffffff;
            padding: 0 30px;
            margin-left: 100px;
        }
        .revokeGeneration {
            width: 103px;
            height: 28px;
            background: #2b7fe0;
            border-radius: 4px;
            cursor: pointer;
            text-align: center;
            color: #ffffff;
            line-height: 28px;
            float: right;
            font-size: 14px;
            color: #ffffff;
            padding: 0 30px;
            margin-right: 100px;
        }
        #s1{
            width: 400px;
            height: 80px;
            border-radius: 5px;
            vertical-align: middle;
        }
        #s2{
            width: 400px;
            height: 80px;
            border-radius: 5px;
            vertical-align: middle;
        }

    </style>
</head>

<body>
<div class="bx">

    <div class="navigation  clearfix juMange" id="hoSet" style="display: block;">
        <div class="left" style="margin-left: 30px">
            <img src="/img/commonTheme/${sessionScope.InterfaceModel}/icon_manageFile.png">
            <div class="news">代考勤设置</div>
        </div>
        <div class="return"><a href="/attendanceWay/attindex">返回</a></div>


        <div style="clear: both;">

        </div>

        <table class="applicable"   style="margin-bottom: 100px">
            <tr >
                <td class="">适用部门：</td>
                <td class="">
                    <input type="hidden" name="" value="">
                    <textarea name="" id="s1" disabled></textarea>
                    <a href="javascript:;" style="margin: 0 10px;" id="a1" class="a1">添加</a>
                    <a href="javascript:;" class="clearS1">清空</a>
                </td>
            </tr>
            <tr>
                <td class="">代考勤人员：</td>
                <td class="">
                    <input type="hidden" name="" value="">
                    <textarea name="" id="s2" disabled></textarea>
                    <a href="javascript:;" style="margin: 0 10px;" id="a2" class="a2">添加</a>
                    <a href="javascript:;"  class="clearS2">清空</a>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <div class="addGeneration">
                        添加代考勤
                    </div>
                    <div class="preserve" style="display: none;">
                        保存
                    </div>
                    <div class="revokeGeneration" style="display: none">
                        撤销
                    </div>
                </td>

            </tr>
        </table>

        <table class="applicableCon" >
            <tr >
                <th nowrap="" align="center">编号</th>
                <th nowrap="" align="center">管辖部门</th>
                <th nowrap="" align="center">代考勤人员</th>
                <th nowrap="" align="center">操作</th>
            </tr>
        </table>



    </div>
</div>
</body>
<script type="text/javascript">

    //选择部门
    $('#a1').click(function(){
        dept_id="s1";
        $.popWindow("../../common/selectDept?allDept=1");
    })

    //选择人员
    $('#a2').click(function(){
        user_id="s2";
        $.popWindow("../../common/selectUser");
    });


    var preserveId
    var preserveMen
    var preserveRen




    //    查询代考勤规则
    $.ajax({
        type:'post',
        url:'/LeaveManager/getLeaveManager',
        dataType:'json',
        data:{
            page:1,
            pageSize:10,
            useFlag:true
        },
        success:function(res){

            var resContent
            var dataObj=res.obj;
            $.each(dataObj,function (i, item) {
                var iNum=i+1;
                resContent+='<tr class="activeNum" mId="'+item.managerId+'">'+
                    '<td nowrap="" align="center">'+iNum+'</td>'+
                    '<td align="center">'+item.deptName+'</td>'+
                    '<td align="center">'+item.userName+'</td>'+
                    '<td nowrap="" align="center">'+
                    '<a class="editGeneration"href="javascript:;"> 编辑</a>'+
                    '<a style="color:crimson;" class="delGeneration" href="javascript:;"> 删除</a>'+
                    '</td>'+
                    '</tr>'
            })
            $(".applicableCon").append(resContent);
            

            //    编辑代考勤规则
            $(".editGeneration").click(function () {

                var fId=$(this).parent().parent().attr("mId");

                preserveId=fId
                $(".applicableCon").hide();
                $(".addGeneration").hide();
                $(".preserve").show();
                $(".revokeGeneration").show();
                console.log(fId)

                $.ajax({
                    type:'post',
                    url:'/LeaveManager/getLeaveManagerById',
                    dataType:'json',
                    data:{
                        managerId:preserveId,
//                        deptIdStr:$("#s1").attr("deptid"),
//                        managers:$("#s2").attr("user_id")
                    },
                    success:function(res){
                      var data= res.object

                        console.log(data)

                        $("#s1").val(data.deptName)
                        $("#s2").val(data.userName)

                    }
                })
            })
            //  删除代考勤规则

            $(".delGeneration").click(function () {

                var fId=$(this).parent().parent().attr("mId");

                $(this).parent().parent().remove()

                $.ajax({
                    type:'post',
                    url:'/LeaveManager/delLeaveManager',
                    dataType:'json',
                    data:{
                        managerId:fId
                    },
                    success:function(res){
                        layer.msg('删除成功！', {icon: 2,time:2000});
                        setTimeout(function(){  window.location.reload(); }, 2000);
                    }
                })
            });
        }
    })

    //保存考勤规则

    $(".preserve").click(function () {
        if($('#s1').val() == ''){
            $.layerMsg({content:'适用部门不能为空',icon:2});
            return false;
        }else  if($('#s2').val() == ''){
            $.layerMsg({content:'代考勤人员不能为空',icon:2});
            return false;
        }


        $.ajax({
            type:'post',
            url:'/LeaveManager/editLeaveManager',
            dataType:'json',
            data:{
                managerId:preserveId,
                deptIdStr:$("#s1").attr("deptid"),
                managers:$("#s2").attr("user_id")
            },
            success:function(res){
                setTimeout(function()
                {  window.location.reload();
                    $(".applicableCon").show();
                    $(".addGeneration").show();
                    $(".preserve").hide();
                }, 2000);
                layer.msg('编辑保存成功！', {icon: 1,time:2000});
//                alert("编辑保存成功！")
            }
        })
    })
    //    添加代考勤规则
    $(".addGeneration").click(function () {

        if($("#s1").attr("deptid")==undefined){
            layer.msg('未选择部门，请重新选择！', {icon: 2,time:2000});
//            alert("未选择部门，请重新选择")
        }else if($("#s2").attr("user_id")==undefined){
            layer.msg('未选择人员，请重新选择！', {icon: 2,time:2000});
//            alert("未选择人员，请重新选择")
        }else if($("#s1").attr("deptid")==""){

            layer.msg('未选择部门，请重新选择！', {icon: 2,time:2000});

//            alert("未选择部门，请重新选择")
        }else if($("#s2").attr("user_id")==""){
            layer.msg('未选择人员，请重新选择！', {icon: 2,time:2000});
//            alert("未选择人员，请重新选择")
        }else {
            $.ajax({
                type:'post',
                url:'/LeaveManager/addLeaveManager',
                dataType:'json',
                data:{
                    deptIdStr:$("#s1").attr("deptid"),
                    managers:$("#s2").attr("user_id")
                    //传递的值为逗号隔开的字符串
                },
                success:function(res){

                    setTimeout(function(){  window.location.reload(); }, 2000);
                    layer.msg('添加成功', {icon: 1,time:2000});
//                    alert(" 添加成功！")
                }

            });
        }

    })
    //撤销考勤规则

    $(".revokeGeneration").click(function () {
        $(".preserve").hide();
        $(".applicableCon").show();
        $(".addGeneration").show();
        window.location.reload();
    })
    //清空选择
    $(".clearS1").click(function () {
        $("#s1").attr('deptid','');
        $("#s1").attr('deptname','');
        $("#s1").attr('privid','');
        $("#s1").attr('userpriv','');
        $("#s1").attr('dataid','');
        $("#s1").attr('username','');
        $("#s1").attr('user_id','');
        $("#s1").attr('userprivname','');
        $("#s1").val('');
    })
    $(".clearS2").click(function () {
        $("#s2").attr('deptid','');
        $("#s2").attr('deptname','');
        $("#s2").attr('privid','');
        $("#s2").attr('userpriv','');
        $("#s2").attr('dataid','');
        $("#s2").attr('username','');
        $("#s2").attr('user_id','');
        $("#s2").attr('userprivname','');
        $("#s2").val('');
    })
</script>

</html>





































